#include <stdio.h>
#include <string.h>
#include <stdlib.h>


void copy_file1(FILE *fp1,FILE *fp2){      //拷贝文件 输入两个文件标识符 将第一个文件标识符所指的文件拷贝到第二个、

	char ch = fgetc (fp1);

	while(ch != EOF){
		fputc(ch,fp2);
		ch = fgetc (fp1);
	}

}

char* which_ID1(char *ID){            //通过他的id找到所在文件位置
	if(ID[0] == '1'){
		return "../manager/";
	}
	else if(ID[0] == '2'){
		return "../service/";
	}
	else{
		return "../customer/";
	}
	
}

char* str_cat1(char *ch1,char *ch2){				//合成字符串
	char *ret = malloc(sizeof(char)*(strlen(ch1)+strlen(ch2)));
	
	strcpy(ret,ch1);

	strcat(ret,ch2);

	return ret;
	
}

int updata(char *ID,char *option,char *data){

	FILE *fp;	
	char *ch = which_ID1(ID);
	
	ch = str_cat1(ch,ID);

	ch = str_cat1(ch,"/");
	
	ch = str_cat1(ch,option);

	fp = fopen (ch,"w");

	if(fp == NULL){
		return 0;
	}

	fputs(data,fp);

	fclose(fp);

	return 1;
}


//void main(void){

//	char ch1[] = "301";
//	char ch2[] = "name";
//	char ch3[] = "swc";

//	updata(ch1,ch2,ch3);

//}
